package org.foreningsgatan.genetics.racers;

import static org.foreningsgatan.genetics.racers.Configuration.*;

import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CheckPoints {
	private Random random;
	private List<Point2D> points;

	public List<Point2D> getPoints() {
		return points;
	}

	private void randomPoints(int count) {
		for (int i = 0; i < count; i++) {
			double a = 2 * Math.PI * i / count;
			double radius = (double) sWidth / 4 + random.nextDouble() * sWidth / 6;

			points.add(new Point2D.Double(radius * Math.cos(a), radius * Math.sin(a)));
		}
	}

	public CheckPoints() {
		this.points = new ArrayList<Point2D>();
		this.random = new Random();

		randomPoints(Configuration.sCheckpoints);
	}

	public Point2D get(int index) {
		index = (int) CommonMath.wrap(index, 0, points.size() - 1);

		return points.get(index);
	}
}
